#include<fstream>
#include"../cpp-httplib/httplib.h"

int main() {
    using namespace httplib;

    Server svr;
    svr.Get("/index", [&](const Request& req, Response& res){
        (void) req;
        std::ifstream ifs("./wwwroot/index.html");    
        if (!ifs.is_open()) {                                                                                                               
            return;    
        }    
        std::string response;    
        while (!ifs.eof()) {    
          std::string tmp;    
          getline(ifs, tmp);    
          response += tmp;     
        }    
        ifs.close();    
        res.status = 200;
        res.set_content(response, "text/html");    
    });
    svr.Get("css/bootstrap.min.css", [&](const Request& req, Response& res){
        (void) req;
        std::ifstream ifs("./wwwroot/css/bootstrap.min.css");    
        if (!ifs.is_open()) {                                                                                                               
            std::cout << "打开失败" << std::endl;
            return;    
        }    
        std::string response;    
        while (!ifs.eof()) {    
          std::string tmp;    
          getline(ifs, tmp);    
          response += tmp;     
        }    
        ifs.close();    
        std::cout << response << std::endl;
        res.status = 200;
        res.set_content(response, "text/css");    
    });

    svr.set_base_dir("./wwwroot", "/");
    svr.listen("0.0.0.0", 8080);

    return 0;
}
